<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Classes  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset="utf-8">
    <script src="js/jquery.min.js" defer></script>
    <script src="js/jazzy.js" defer></script>
    
    <script src="js/lunr.min.js" defer></script>
    <script src="js/typeahead.jquery.js" defer></script>
    <script src="js/jazzy.search.js" defer></script>
  </head>
  <body>

    <a name="//apple_ref/swift/Section/Classes" class="dashAnchor"></a>

    <a title="Classes  Reference"></a>

    <header class="header">
      <p class="header-col header-col--primary">
        <a class="header-link" href="index.html">
          Kitura Docs
        </a>
         (99% documented)
      </p>
    
      <p class="header-col--secondary">
        <form role="search" action="search.json">
          <input type="text" placeholder="Search documentation" data-typeahead>
        </form>
      </p>
    
        <p class="header-col header-col--secondary">
          <a class="header-link" href="https://github.com/Kitura/Kitura/">
            <img class="header-icon" src="img/gh.png"/>
            View on GitHub
          </a>
        </p>
    
    </header>

    <p class="breadcrumbs">
      <a class="breadcrumb" href="index.html">Kitura Reference</a>
      <img class="carat" src="img/carat.png" />
      Classes  Reference
    </p>

    <div class="content-wrapper">
      <nav class="navigation">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/BodyParser.html">BodyParser</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/BodyParserMultiValue.html">BodyParserMultiValue</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/ContentType.html">ContentType</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/Kitura.html">Kitura</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/Router.html">Router</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/RouterMiddlewareGenerator.html">RouterMiddlewareGenerator</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/RouterRequest.html">RouterRequest</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/RouterResponse.html">RouterResponse</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/StaticFileServer.html">StaticFileServer</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/StaticFileServer/CacheOptions.html">– CacheOptions</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/StaticFileServer/Options.html">– Options</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Enums.html">Enumerations</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Enums/JSONPError.html">JSONPError</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Enums/LinkParameter.html">LinkParameter</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Enums/ParsedBody.html">ParsedBody</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Enums/RouterMethod.html">RouterMethod</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Extensions.html">Extensions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/DecodingError.html">DecodingError</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Protocols/ResponseHeadersSetter.html">ResponseHeadersSetter</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Protocols/RouterMiddleware.html">RouterMiddleware</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Protocols/TypeSafeMiddleware.html">TypeSafeMiddleware</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Structs.html">Structures</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/AdditionalCookieAttribute.html">AdditionalCookieAttribute</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/CodableHelpers.html">CodableHelpers</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/HTTPVersion.html">HTTPVersion</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/Headers.html">Headers</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/MediaType.html">MediaType</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/MediaType/TopLevelType.html">– TopLevelType</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/Part.html">Part</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/Part/HeaderType.html">– HeaderType</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/SSLConfig.html">SSLConfig</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/SwaggerDocument.html">SwaggerDocument</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Typealiases.html">Type Aliases</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:6Kitura14HTTPStatusCodea">HTTPStatusCode</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:6Kitura16LifecycleHandlera">LifecycleHandler</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:6Kitura12RequestErrora">RequestError</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:6Kitura13RouterHandlera">RouterHandler</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:6Kitura22RouterParameterHandlera">RouterParameterHandler</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:6Kitura13ServerOptionsa">ServerOptions</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Typealiases.html#/s:6Kitura17WrittenDataFiltera">WrittenDataFilter</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">

        <section class="section">
          <div class="section-content top-matter">
            <h1>Classes</h1>
            <p>The following classes are available globally.</p>

          </div>
        </section>

        <section class="section">
          <div class="section-content">
            <div class="task-group">
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Kitura6RouterC"></a>
                    <a name="//apple_ref/swift/Class/Router" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Kitura6RouterC">Router</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p><code>Router</code> provides the external interface for routing requests to
the appropriate code to handle them. This includes:</p>

<ul>
<li>Routing requests to closures of type <code><a href="Typealiases.html#/s:6Kitura13RouterHandlera">RouterHandler</a></code></li>
<li>Routing requests to the handle function of classes that implement the
<code><a href="Protocols/RouterMiddleware.html">RouterMiddleware</a></code> protocol.</li>
<li>Routing requests to a <code>TemplateEngine</code> to generate the appropriate output.</li>
<li>Serving the landing page when someone makes an HTTP request with a path of slash (/).</li>
</ul>

                        <a href="Classes/Router.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">Router</span></code></pre>
<pre class="highlight swift"><code><span class="kd">extension</span> <span class="kt">Router</span> <span class="p">:</span> <span class="kt"><a href="Protocols/RouterMiddleware.html">RouterMiddleware</a></span></code></pre>
<pre class="highlight swift"><code><span class="kd">extension</span> <span class="kt">Router</span> <span class="p">:</span> <span class="kt">ServerDelegate</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6KituraAAC"></a>
                    <a name="//apple_ref/swift/Class/Kitura" class="dashAnchor"></a>
                    <a class="token" href="#/s:6KituraAAC">Kitura</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Facilities for creating, starting and stopping Kitura-based servers.</p>
<h3 id='usage-example' class='heading'>Usage Example:</h3>

<p>In this example, a <code><a href="Classes/Router.html">Router</a></code> is created, and a single route registered that responds to an HTTP GET request on &ldquo;/&rdquo; with a plain text response.
An HTTP server is created on port 8080, and is started with the <code>Kitura.run()</code> function (note that this function does not return).
The route can then be accessed by visiting <code>http://localhost:8080</code>.</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">router</span> <span class="o">=</span> <span class="kt">Router</span><span class="p">()</span>
<span class="n">router</span><span class="o">.</span><span class="nf">get</span><span class="p">(</span><span class="s">"/"</span><span class="p">)</span> <span class="p">{</span> <span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">next</span> <span class="k">in</span>
    <span class="n">response</span><span class="o">.</span><span class="nf">send</span><span class="p">(</span><span class="s">"Hello world"</span><span class="p">)</span>
    <span class="nf">next</span><span class="p">()</span>
<span class="p">}</span>
<span class="kt">Kitura</span><span class="o">.</span><span class="nf">addHTTPServer</span><span class="p">(</span><span class="nv">onPort</span><span class="p">:</span> <span class="mi">8080</span><span class="p">,</span> <span class="nv">onAddress</span><span class="p">:</span> <span class="s">"localhost"</span><span class="p">,</span> <span class="nv">with</span><span class="p">:</span> <span class="n">router</span><span class="p">)</span>
<span class="kt">Kitura</span><span class="o">.</span><span class="nf">run</span><span class="p">()</span>
</code></pre>

                        <a href="Classes/Kitura.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">Kitura</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/RouterMiddlewareGenerator"></a>
                <a name="//apple_ref/swift/Section/RouterMiddlewareGenerator" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/RouterMiddlewareGenerator"></a>
                  <h3 class="section-name"><p>RouterMiddlewareGenerator</p>
</h3>
                </div>
              </div>
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Kitura25RouterMiddlewareGeneratorC"></a>
                    <a name="//apple_ref/swift/Class/RouterMiddlewareGenerator" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Kitura25RouterMiddlewareGeneratorC">RouterMiddlewareGenerator</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Create an on the fly <code><a href="Protocols/RouterMiddleware.html">RouterMiddleware</a></code> from a <code><a href="Typealiases.html#/s:6Kitura13RouterHandlera">RouterHandler</a></code> closure.</p>

                        <a href="Classes/RouterMiddlewareGenerator.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">RouterMiddlewareGenerator</span> <span class="p">:</span> <span class="kt"><a href="Protocols/RouterMiddleware.html">RouterMiddleware</a></span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/RouterRequest"></a>
                <a name="//apple_ref/swift/Section/RouterRequest" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/RouterRequest"></a>
                  <h3 class="section-name"><p>RouterRequest</p>
</h3>
                </div>
              </div>
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Kitura13RouterRequestC"></a>
                    <a name="//apple_ref/swift/Class/RouterRequest" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Kitura13RouterRequestC">RouterRequest</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>The <code>RouterRequest</code> class is used to interact with incoming HTTP requests to the Router.
It contains and allows access to the request&rsquo;s <code><a href="Structs/Headers.html">Headers</a></code> and <code>Body</code> as well as other properties of the request.
It can also perform content negotiation based on the request’s &ldquo;Accept&rdquo; header.</p>
<h3 id='usage-example' class='heading'>Usage Example:</h3>

<p>In this example &ldquo;request&rdquo; is an instance of the class <code>RouterRequest</code>.
It is used by the server to read the body of the request as a String and send it back to the user.</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">router</span> <span class="o">=</span> <span class="kt">Router</span><span class="p">()</span>
<span class="n">router</span><span class="o">.</span><span class="nf">post</span><span class="p">(</span><span class="s">"/"</span><span class="p">)</span> <span class="p">{</span> <span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">next</span> <span class="k">in</span>
    <span class="k">let</span> <span class="nv">body</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="nf">readString</span><span class="p">()</span>
    <span class="n">response</span><span class="o">.</span><span class="nf">send</span><span class="p">(</span><span class="n">body</span><span class="p">)</span>
    <span class="nf">next</span><span class="p">()</span>
<span class="p">}</span>
</code></pre>

                        <a href="Classes/RouterRequest.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">RouterRequest</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/RouterResponse"></a>
                <a name="//apple_ref/swift/Section/RouterResponse" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/RouterResponse"></a>
                  <h3 class="section-name"><p>RouterResponse</p>
</h3>
                </div>
              </div>
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Kitura14RouterResponseC"></a>
                    <a name="//apple_ref/swift/Class/RouterResponse" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Kitura14RouterResponseC">RouterResponse</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>The RouterResponse class is used to define and work with the response that will be sent by the <code><a href="Classes/Router.html">Router</a></code>.
It contains and allows access to the HTTP response code (e.g. 404 &ldquo;Not Found&rdquo;), the HTTP <code><a href="Structs/Headers.html">Headers</a></code>
and the body of the response.
It can also render template files, using a template engine registered to the router.</p>
<h3 id='usage-example' class='heading'>Usage Example:</h3>

<p>In this example &ldquo;response&rdquo; is an instance of the class <code>RouterResponse</code>.
The content type and status code of the response are set.
The String &ldquo;Hello world&rdquo; is added to the body and the response is transmitted.</p>
<pre class="highlight swift"><code><span class="n">router</span><span class="o">.</span><span class="nf">get</span><span class="p">(</span><span class="s">"/example"</span><span class="p">)</span> <span class="p">{</span> <span class="n">_</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">next</span> <span class="k">in</span>
    <span class="n">response</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s">"Content-Type"</span><span class="p">]</span> <span class="o">=</span> <span class="s">"text/html"</span>
    <span class="n">response</span><span class="o">.</span><span class="nf">status</span><span class="p">(</span><span class="o">.</span><span class="kt">OK</span><span class="p">)</span>
    <span class="k">try</span> <span class="n">response</span><span class="o">.</span><span class="nf">send</span><span class="p">(</span><span class="s">"Hello world"</span><span class="p">)</span><span class="o">.</span><span class="nf">end</span><span class="p">()</span>
<span class="p">}</span>
</code></pre>

                        <a href="Classes/RouterResponse.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">RouterResponse</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/BodyParser"></a>
                <a name="//apple_ref/swift/Section/BodyParser" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/BodyParser"></a>
                  <h3 class="section-name"><p>BodyParser</p>
</h3>
                </div>
              </div>
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Kitura10BodyParserC"></a>
                    <a name="//apple_ref/swift/Class/BodyParser" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Kitura10BodyParserC">BodyParser</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>The <code>BodyParser</code> parses the body of the request prior to sending it to the handler. It reads the Content-Type of the message header and populates the <code><a href="Classes/RouterRequest.html">RouterRequest</a></code> body field with a corresponding <code><a href="Enums/ParsedBody.html">ParsedBody</a></code> enumeration.</p>

<p>In order for the BodyParser to be used it must first be registered with any routes that are interested in the <code><a href="Enums/ParsedBody.html">ParsedBody</a></code> payload.</p>
<h3 id='parsedbody-enumeration' class='heading'>ParsedBody enumeration:</h3>

<p>The mappings from the incoming Content-Type to an internal representation of the body are as follows:</p>
<pre class="highlight swift"><code>   <span class="o">.</span><span class="nf">json</span><span class="p">([</span><span class="kt">String</span><span class="p">:</span> <span class="kt">Any</span><span class="p">])</span>          <span class="c1">// "application/json"</span>
   <span class="o">.</span><span class="nf">text</span><span class="p">(</span><span class="kt">String</span><span class="p">)</span>                 <span class="c1">// "text/*"</span>
   <span class="o">.</span><span class="nf">urlEncoded</span><span class="p">([</span><span class="kt">String</span><span class="p">:</span><span class="kt">String</span><span class="p">])</span>  <span class="c1">// "application/x-www-form-urlencoded"</span>
   <span class="o">.</span><span class="nf">multipart</span><span class="p">([</span><span class="kt">Part</span><span class="p">])</span>            <span class="c1">// "multipart/form-data"</span>
   <span class="o">.</span><span class="nf">raw</span><span class="p">(</span><span class="kt">Data</span><span class="p">)</span>                    <span class="c1">// Any other Content-Type</span>
</code></pre>

<p>Each case has a corresponding convenience property, e.g. <code>asURLEncoded: [String:String]</code>, for accessing the associated data.</p>

<p><strong>Note</strong>: If you have not declared a Content-Type header, <code><a href="Enums/ParsedBody.html">ParsedBody</a></code> will be <code>nil</code>.</p>
<h3 id='usage-example' class='heading'>Usage Example:</h3>

<p>In this example, all routes to the BodyParser middleware are registered to the <code>BodyParser</code> middleware. A request with &ldquo;application/json&rdquo;, ContentType header is received. It is then parsed as JSON and the value for &ldquo;name&rdquo; is returned in the response.</p>
<pre class="highlight swift"><code><span class="n">router</span><span class="o">.</span><span class="nf">all</span><span class="p">(</span><span class="s">"/name"</span><span class="p">,</span> <span class="nv">middleware</span><span class="p">:</span> <span class="kt">BodyParser</span><span class="p">())</span>
<span class="n">router</span><span class="o">.</span><span class="nf">post</span><span class="p">(</span><span class="s">"/name"</span><span class="p">)</span> <span class="p">{</span> <span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">,</span> <span class="n">next</span> <span class="k">in</span>
    <span class="k">guard</span> <span class="k">let</span> <span class="nv">jsonBody</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">parsedBody</span><span class="p">?</span><span class="o">.</span><span class="n">asJSON</span> <span class="k">else</span> <span class="p">{</span>
        <span class="nf">next</span><span class="p">()</span>
        <span class="k">return</span>
    <span class="p">}</span>
    <span class="k">let</span> <span class="nv">name</span> <span class="o">=</span> <span class="n">jsonBody</span><span class="p">[</span><span class="s">"name"</span><span class="p">]</span> <span class="k">as?</span> <span class="kt">String</span> <span class="p">??</span> <span class="s">""</span>
    <span class="k">try</span> <span class="n">response</span><span class="o">.</span><span class="nf">send</span><span class="p">(</span><span class="s">"Hello </span><span class="se">\(</span><span class="n">name</span><span class="se">)</span><span class="s">"</span><span class="p">)</span><span class="o">.</span><span class="nf">end</span><span class="p">()</span>
<span class="p">}</span>
</code></pre>

<p><strong>Note</strong>: When using Codable Routing in Kitura 2.x the BodyParser should not be registered to any codable routes (doing so will log the following error &ldquo;No data in request. Codable routes do not allow the use of a BodyParser.&rdquo; and the route handler will not be executed).</p>

                        <a href="Classes/BodyParser.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">BodyParser</span> <span class="p">:</span> <span class="kt"><a href="Protocols/RouterMiddleware.html">RouterMiddleware</a></span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Kitura20BodyParserMultiValueC"></a>
                    <a name="//apple_ref/swift/Class/BodyParserMultiValue" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Kitura20BodyParserMultiValueC">BodyParserMultiValue</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>The <code>BodyParserMultiValue</code> is a subclass of <code><a href="Classes/BodyParser.html">BodyParser</a></code>, which differs in behaviour
when decoding urlencoded parameters with multiple values (such as <code>&amp;a=1&amp;a=2</code>).</p>

<p>Whereas <code><a href="Classes/BodyParser.html">BodyParser</a></code> will produce a comma-separated list of values: <code>[&quot;a&quot;: &quot;1,2&quot;]</code>
which may be accessed by <code>ParsedBody.urlEncoded</code>, <code>BodyParserMultiValue</code> will
produce an array of values: <code>[&quot;a&quot;: [&quot;1&quot;, &quot;2&quot;]]</code>, accessed by <code>ParsedBody.urlEncodedMultiValue</code>.</p>

<p>This enables you to accept multiple values which may themselves contain commas.</p>

                        <a href="Classes/BodyParserMultiValue.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">BodyParserMultiValue</span> <span class="p">:</span> <span class="kt"><a href="Classes/BodyParser.html">BodyParser</a></span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/ContentType"></a>
                <a name="//apple_ref/swift/Section/ContentType" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/ContentType"></a>
                  <h3 class="section-name"><p>ContentType</p>
</h3>
                </div>
              </div>
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Kitura11ContentTypeC"></a>
                    <a name="//apple_ref/swift/Class/ContentType" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Kitura11ContentTypeC">ContentType</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>The <code>ContentType</code> class provides functions to determine the MIME content type for a given file extension. The user can pass in a complete file name e.g. &ldquo;foo.png&rdquo; or just the file extension e.g. &ldquo;png&rdquo;, or they can pass in both a MIME content type and a file extension and query whether they match.</p>
<h3 id='usage-example' class='heading'>Usage Example:</h3>

<p>In this example, a <code>ContentType</code> instance is initialised called contentType. This instance is then used to obtain the MIME content type of the file &ldquo;foo.png&rdquo;, which is identified as &ldquo;image/png&rdquo;.</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">contentType</span> <span class="o">=</span> <span class="kt">ContentType</span><span class="o">.</span><span class="n">sharedInstance</span>
<span class="k">let</span> <span class="nv">result</span> <span class="o">=</span> <span class="n">contentType</span><span class="o">.</span><span class="nf">getContentType</span><span class="p">(</span><span class="nv">forFileName</span><span class="p">:</span> <span class="s">"foo.png"</span><span class="p">)</span>
<span class="nf">print</span><span class="p">(</span><span class="kt">String</span><span class="p">(</span><span class="nv">describing</span><span class="p">:</span> <span class="n">result</span><span class="p">))</span>
<span class="c1">// Prints Optional("image/png")</span>
</code></pre>

                        <a href="Classes/ContentType.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">ContentType</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/StaticFileServer"></a>
                <a name="//apple_ref/swift/Section/StaticFileServer" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/StaticFileServer"></a>
                  <h3 class="section-name"><p>StaticFileServer</p>
</h3>
                </div>
              </div>
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:6Kitura16StaticFileServerC"></a>
                    <a name="//apple_ref/swift/Class/StaticFileServer" class="dashAnchor"></a>
                    <a class="token" href="#/s:6Kitura16StaticFileServerC">StaticFileServer</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>A router middleware that serves static files from a given path.
By default, it will serve files from the &ldquo;/public&rdquo; directory.</p>
<h3 id='usage-example' class='heading'>Usage Example:</h3>

<p>The example below creates and registers a <code>StaticFileServer</code> on the &ldquo;/example&rdquo; route.
When the router is running, A user can make a request that matches the &ldquo;/example&rdquo; path (e.g. localhost:8080/example/hello.html).
The static file server would look inside its &ldquo;/files&rdquo; folder for a file with the same name as the path following &ldquo;/example&rdquo;  (e.g. &ldquo;hello.html&rdquo;).
If a file is found it is sent as a response to that request, otherwise the next handler is called.</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">router</span> <span class="o">=</span> <span class="kt">Router</span><span class="p">()</span>
<span class="n">router</span><span class="o">.</span><span class="nf">all</span><span class="p">(</span><span class="s">"/example"</span><span class="p">,</span> <span class="nv">middleware</span><span class="p">:</span> <span class="kt">StaticFileServer</span><span class="p">(</span><span class="nv">path</span><span class="p">:</span> <span class="s">"./files"</span><span class="p">))</span>
</code></pre>

                        <a href="Classes/StaticFileServer.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">open</span> <span class="kd">class</span> <span class="kt">StaticFileServer</span> <span class="p">:</span> <span class="kt"><a href="Protocols/RouterMiddleware.html">RouterMiddleware</a></span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </section>

      </article>
    </div>
    <section class="footer">
      <p>&copy; 2021 <a class="link" href="" target="_blank" rel="external">IBM &amp; Kitura project authors</a>. All rights reserved. (Last updated: 2021-01-25)</p>
      <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
    </section>
  </body>
</div>
</html>
